package com.xinsoft.entity.dto;

import cn.hutool.core.util.ObjectUtil;
import com.xinsoft.entity.po.SysUser;
import lombok.Data;
import org.springframework.util.ObjectUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *  @author: π
 *  用户
 */
@Data
public class KisUserDto {

    private String  FItemId;
    private String  FNumber;
    private String  FUserId;
    private String  FName;
    private String  FEmpGroup;
    private String  FEmpGroup_FName;
    private String  FDepartmentID_FName;
    private String  FDepartmentID;
    private String  FGender;
    private String  FGender_FName;
    private String  FBirthDay;
    private String  FDegree;
    private String  FDegree_FName;
    private String  FPhone;
    private String  FMobilePhone;
    private String  FID;
    private String  FDuty;
    private String  FDuty_FName;
    private String  FHireDate;
    private String  FLeaveDate;
    private String  FNAME;
    private String  FAddress;
    private String  FEmail;
    private String  FNote;



//    {
//        "FRECORDS": 1,
//            "FItemId": 10537,
//            "FNumber": "A154",
//            "FName": "刘江",
//            "FParentId": 0,
//            "FEmpGroup": 0,
//            "FEmpGroup_FName": null,
//            "FDepartmentID": 4076,
//            "FDepartmentID_FName": "质量部",
//            "FGender": 1068,男  1069女
//            "FGender_FName": "男",
//            "FBirthDay": "2000-01-03T00:00:00",
//            "FDegree": 401,
//            "FDegree_FName": "大专",
//            "FPhone": null,
//            "FMobilePhone": "13179579008",
//            "FID": "320723200001033618",
//            "FDuty": 0,
//            "FDuty_FName": null,
//            "FHireDate": "2022-02-21T00:00:00",
//            "FLeaveDate": null,
//            "FAddress": null,
//            "FEmail": null,
//            "FNote": null
//    }
//    "FItemId":"内码"
//            "FNumber":"编码"
//            "FName":"名称"
//            "FEmpGroup":"职员类别"
//            "FEmpGroup_FName":"职员类别"
//            "FDepartmentID_FName":"部门名称"
//            "FDepartmentID":"部门名称"
//            "FGender":"性别"
//            "FGender_FName":"性别"
//            "FBirthDay":"出生日期"
//            "FDegree":"文化程度"
//            "FDegree_FName":"文化程度"
//            "FPhone":"电话"
//            "FMobilePhone":"移动电话"
//            "FID":"身份证号码"
//            "FDuty":"职务"
//            "FDuty_FName":"职务"
//            "FHireDate":"入职日期"
//            "FLeaveDate":"离职日期"
//            "FNAME":"开户银行及账号"
//            "FAddress":"住址"
//            "FEmail":"电子邮件"
//            "FNote":"备注"
    public static SysUser voToPo(KisUserDto vo) {
        if (vo == null) {
            return null;
        }
        String pattern = "yyyy-MM-dd";
        SimpleDateFormat sdf =new SimpleDateFormat(pattern);

        SysUser sysUser = new SysUser();
        sysUser.setId(new Integer(vo.getFItemId()));
//        sysUser.setUserId2(ObjectUtils.isEmpty(vo.getFUserId()) ? null : Long.parseLong(vo.getFUserId()));
        sysUser.setDeptId(ObjectUtil.isEmpty(vo.getFDepartmentID()) ? null : new Integer(vo.getFDepartmentID()));
        sysUser.setUsername(vo.getFName());
        sysUser.setRealName(vo.getFName());
        sysUser.setEmail(vo.getFEmail());
        sysUser.setMobile(ObjectUtil.isEmpty(vo.getFMobilePhone()) ? null :vo.getFMobilePhone() );
        //离职日期如果有则为离职
        sysUser.setStatus(ObjectUtil.isEmpty(vo.getFLeaveDate()) ? 1 : 0);
        try {
            sysUser.setBirth(ObjectUtil.isEmpty(vo.getFBirthDay()) ? null : sdf.parse(vo.getFBirthDay()));
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
        sysUser.setLiveAddress(vo.getFAddress());
        sysUser.setRegisterFrom(3l);
        //todo 密码
        sysUser.setSex(ObjectUtil.isEmpty(vo.getFGender()) ? null : (
                vo.getFGender().equals("1068") ? 1 : 0 ));
        return sysUser;
    }
}
